home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / nihcl-30.lha / nihcl-3.0 / vector / LongVect.c < prev    next >
C/C++ Source or Header  |  1990-05-16  |  2KB  |  74 lines

  1. /* LongVect.c -- Data type-specific functions for class LongVec
  2.  
  3.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  4.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  5.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  6.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  7.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  8.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  9.  
  10. Author:
  11.         Ted Persky
  12.     Bg. 12A, Rm. 2031
  13.     Computer Systems Laboratory
  14.     Division of Computer Research and Technology
  15.     National Institutes of Health
  16.     Bethesda, Maryland 20892
  17.     Phone: (301) 496-2963
  18.     uucp: uunet!nih-csl!tpersky
  19.     Internet: tpersky@alw.nih.gov
  20.  
  21. Function:
  22.     
  23. Data type -specific functions for class LongVec.
  24.  
  25. Modification History:
  26.  
  27. $Log:    LongVect.c,v $
  28.  * Revision 3.0  90/05/16  23:00:36  kgorlen
  29.  * Release for 1st edition.
  30.  * 
  31. */
  32.  
  33. #include "LongVec.h"
  34. #include "nihclconfig.h"
  35. #include "nihclIO.h"
  36. #include <iomanip.h>
  37. #include <libc.h>
  38.  
  39. #define    THIS    LongVec
  40. #define    BASE    Vector
  41.  
  42. static int typeCmp(const void* a, const void* b)
  43. {
  44.     return *(const int*)a-*(const int*)b;
  45. }
  46.  
  47. void THIS::sort()
  48. {
  49.     qsort(v,n,sizeof(THIS),typeCmp);
  50. }
  51.  
  52. unsigned THIS::hash() const
  53. {
  54.     unsigned h = n;
  55.     unsigned i = n;
  56.     long* vv = v;
  57.     while (i--) h ^= (unsigned)*vv++;
  58.     return h;
  59. }
  60.  
  61. void THIS::printOn(ostream& strm) const
  62. {
  63.     for (int i=0; i<n; i++) {
  64.         if (i>0 && (i%8 == 0)) strm << "\n\t";
  65.         strm << setw(10) << dec << v[i];
  66.     }
  67. }
  68.  
  69. void THIS::scanFrom(istream& strm)
  70. {
  71.     extern const int NIHCL_NYET;
  72.     setError(NIHCL_NYET,DEFAULT,className(),"scanFrom");
  73. }
  74.